#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "fn_runEvent.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_var_name","_event_params","_event_unique_name","_handler"];
DEFAULT_PARAM(_var_name,0,"");
DEFAULT_PARAM(_event_params,1,[]);

if (!isnull GVAR(ObjectStore)) then {
	if (IS_ARRAY(_event_params) && {count _event_params > 1}) then {
		_event_unique_name = format["%1_%2",QGVAR(event),toUpper(_event_params select 0)];
		_handler = GVAR(ObjectStore) getVariable _event_unique_name;
		TRACE_1("Handler",!isnil "_handler");
		if (!isnil "_handler") then {
			TRACE_1("Running Event",_event_params);
			(_event_params select 1) call _handler;
		};
	} else {
		ERROR_1("Invalid Event Params",_event_params);
	};
} else {
	ERROR("ObjectStore does not exist");
};

TRACE("End");
TMFPROFILERSTOP;
